package com.soft.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.soft.entity.TAdmin;
import com.soft.dao.TAdminDao;
import com.soft.entity.TUser;
import com.soft.service.TAdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TAdmin)表服务实现类
 *
 * @author makejava
 * @since 2021-12-24 13:58:25
 */
@Service("tAdminService")
public class TAdminServiceImpl implements TAdminService {
    @Resource
    private TAdminDao tAdminDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TAdmin queryById(Long id) {
        return this.tAdminDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<TAdmin> queryAllByLimit(int offset, int limit) {
        return this.tAdminDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public TAdmin insert(TAdmin tAdmin) {
        this.tAdminDao.insert(tAdmin);
        return tAdmin;
    }

    /**
     * 修改数据
     *
     * @param tAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public TAdmin update(TAdmin tAdmin) {
        this.tAdminDao.update(tAdmin);
        return this.queryById(tAdmin.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tAdminDao.deleteById(id) > 0;
    }

    @Override
    public TAdmin queryByName(String username) {

        return this.tAdminDao.queryByName(username);
    }

    @Override
    public PageInfo<TAdmin> findAll(int pageNum, int  pageSize){
        PageHelper.startPage(pageNum,  pageSize);
        List<TAdmin> list = this.tAdminDao.findAll();
        PageInfo<TAdmin> pageInfo = new PageInfo<TAdmin>(list);
        return pageInfo;
    }
}